package cn.gjculture.shopping.api.dao;

import cn.gjculture.shopping.api.entity.Pay;
import cn.gjculture.shopping.api.entity.SubAccount;
import cn.gjculture.shopping.api.entity.SupplierSubAccount;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface PayDao {

    @Insert("insert into pay(payId,thirdSwiftNumber,thirdType,orderId,amount,insertTime,payTime,payType,inAndOut,success,isRefund,sonMerNo,customerId,swiftNumber) " +
            "values(#{payId},#{thirdSwiftNumber},#{thirdType},#{orderId},#{amount},#{insertTime},#{payTime},#{payType},#{inAndOut},#{success},#{isRefund},#{sonMerNo},#{customerId},#{swiftNumber})")
    int insert(Pay pay);

    @Select("select * from pay where orderId=#{orderId}")
    Pay queryByOrderId(String orderId);

    @Select("select * from subaccount where customerId=#{customerId} and `status`>1")
    List<SubAccount> querySubAccount(String customerId);

    @Select("select * from suppliersubaccount where `status`=#{status}")
    List<SupplierSubAccount> querySupplierSubAccount(int status);

    @Update("update suppliersubaccount set `status`=#{s.status},payId=#{payId},payTime=#{payTime}  where supplierSubAccountId=#{s.supplierSubAccountId}")
    int updateStatusSupplierSubAccount(SupplierSubAccount s, String payId, long payTime);

    @Update("update subaccount set `status`=#{status} where orderId=#{orderId}")
    int updateSubAccountByOrderId(SubAccount sub);

    @Update("update suppliersubaccount set `status`=#{s.status} where orderId=#{orderId}")
    int updateSupplierSubAccount();

    @Select("select * from pay where payId=#{payId}")
    Pay queryById(String payId);
}
